Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/repository/src/commonMain/kotlin/org/meshtastic/core/repository/ServiceRepository.kt bf929c20f274232e0eb8ddc19b2dc82403e99e5b (bf929c20) Text, 8.24 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.repository

Tff7b72import T7ee787co.touchlab.kermit.Severity
Tff7b72import T7ee787kotlinx.coroutines.flow.Flow
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787org.meshtastic.core.model.ConnectionState
Tff7b72import T7ee787org.meshtastic.core.model.service.LockdownState
Tff7b72import T7ee787org.meshtastic.core.model.service.LockdownTokenInfo
Tff7b72import T7ee787org.meshtastic.core.model.service.TracerouteResponse
Tff7b72import T7ee787org.meshtastic.proto.ClientNotification
Tff7b72import T7ee787org.meshtastic.proto.MeshPacket

T8b949e/**
* Interface for managing background service state, connection status, and mesh events.
*
* This repository acts as the primary data bridge between the long-running mesh service and the UI/Feature layers. It
* maintains reactive flows for connection status, error messages, and incoming mesh traffic.
*
* **Connection state contract:** [connectionState] is the **canonical, app-level** connection state that all UI,
* feature modules, and ViewModels should observe. It incorporates handshake progress, light-sleep policy, and transport
* reconciliation — unlike [RadioInterfaceService.connectionState], which only reflects the raw hardware link status.
* The [MeshConnectionManager] is the sole writer of this state; it bridges [RadioInterfaceService.connectionState]
* changes into app-level transitions via [setConnectionState].
*
* @see RadioInterfaceService.connectionState
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooManyFunctionsTa5d6ff"Tb4b4b4)
Tff7b72interface T56d364ServiceRepository Tb4b4b4:
Te6edf3ConnectionStateProviderTb4b4b4,
Te6edf3TracerouteResponseProviderTb4b4b4,
Te6edf3NeighborInfoResponseProviderTb4b4b4,
Te6edf3ServiceStateWriter Tb4b4b4{
T8b949e/**
* Canonical app-level connection state.
*
* This is the **single source of truth** for connection status across the entire application. All UI components,
* feature modules, and ViewModels should observe this flow — never [RadioInterfaceService.connectionState].
*
* State transitions are managed exclusively by [MeshConnectionManager], which reconciles transport-level events
* with handshake progress and device sleep policy:
* - [ConnectionState.Disconnected] — no active connection to a radio
* - [ConnectionState.Connecting] — transport is up, mesh handshake (config + node-info) in progress
* - [ConnectionState.Connected] — handshake complete, radio fully operational
* - [ConnectionState.DeviceSleep] — radio entered light-sleep (transient disconnect)
*
* @see RadioInterfaceService.connectionState
*/
Tff7b72override Tff7b72val Te6edf3connectionStateTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3ConnectionStateTff7b72>

T8b949e/**
* Updates the canonical app-level connection state.
*
* **This should only be called by [MeshConnectionManager].** Direct mutation from other components would bypass the
* transport-to-app reconciliation logic and create state inconsistencies.
*
* @param connectionState The new [ConnectionState].
*/
Tff7b72override Tff7b72fun Td2a8ffsetConnectionStateTb4b4b4(Te6edf3connectionStateTb4b4b4: Te6edf3ConnectionStateTb4b4b4)

T8b949e/**
* Reactive flow of high-level client notifications.
*
* These represent events from the mesh client that may require UI feedback.
*/
Tff7b72val Te6edf3clientNotificationTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3ClientNotification?Tff7b72>

T8b949e/**
* Sets the current client notification.
*
* @param notification The [ClientNotification] to display or act upon.
*/
Tff7b72override Tff7b72fun Td2a8ffsetClientNotificationTb4b4b4(Te6edf3notificationTb4b4b4: Te6edf3ClientNotification?Tb4b4b4)

T8b949e/** Clears the current client notification. */
Tff7b72override Tff7b72fun Td2a8ffclearClientNotificationTb4b4b4(Tb4b4b4)

T8b949e/**
* Reactive flow of human-readable error messages.
*
* These are typically shown as snackbars or dialogs in the UI.
*/
Tff7b72val Te6edf3errorMessageTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657String?Tff7b72>

T8b949e/**
* Sets an error message to be displayed.
*
* @param text The error message text.
* @param severity The [Severity] level of the error.
*/
Tff7b72override Tff7b72fun Td2a8ffsetErrorMessageTb4b4b4(Te6edf3textTb4b4b4: Tffa657StringTb4b4b4, Te6edf3severityTb4b4b4: Te6edf3SeverityTb4b4b4)

T8b949e/** Clears the current error message. */
Tff7b72override Tff7b72fun Td2a8ffclearErrorMessageTb4b4b4(Tb4b4b4)

T8b949e/**
* Reactive flow of connection progress messages.
*
* Used during the handshake and config loading phase to provide status updates to the user.
*/
Tff7b72val Te6edf3connectionProgressTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657String?Tff7b72>

T8b949e/**
* Sets the connection progress message.
*
* @param text The progress description (e.g., "Downloading Node DB...").
*/
Tff7b72override Tff7b72fun Td2a8ffsetConnectionProgressTb4b4b4(Te6edf3textTb4b4b4: Tffa657StringTb4b4b4)

T8b949e/**
* Flow of all raw [MeshPacket] objects received from the mesh.
*
* Subscribing to this flow allows components to react to any incoming traffic. The underlying implementation may be
* backed by a hot shared flow, but this API intentionally exposes only the [Flow] interface. That implementation
* detail is hidden via [kotlinx.coroutines.flow.SharedFlow.asFlow] (kotlinx.coroutines 1.11+).
*/
Tff7b72val Te6edf3meshPacketFlowTb4b4b4: Te6edf3FlowTff7b72<Te6edf3MeshPacketTff7b72>

T8b949e/**
* Emits a mesh packet into the flow.
*
* Called by the packet processor when new data arrives from the radio.
*
* @param packet The received [MeshPacket].
*/
Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffemitMeshPacketTb4b4b4(Te6edf3packetTb4b4b4: Te6edf3MeshPacketTb4b4b4)

T8b949e/** Reactive flow of the most recent traceroute result. */
Tff7b72override Tff7b72val Te6edf3tracerouteResponseTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3TracerouteResponse?Tff7b72>

T8b949e/**
* Sets the traceroute response.
*
* @param value The [TracerouteResponse] result.
*/
Tff7b72override Tff7b72fun Td2a8ffsetTracerouteResponseTb4b4b4(Te6edf3valueTb4b4b4: Te6edf3TracerouteResponse?Tb4b4b4)

T8b949e/** Clears the current traceroute response. */
Tff7b72override Tff7b72fun Td2a8ffclearTracerouteResponseTb4b4b4(Tb4b4b4)

T8b949e/** Reactive flow of the most recent neighbor info response (formatted string). */
Tff7b72override Tff7b72val Te6edf3neighborInfoResponseTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657String?Tff7b72>

T8b949e/**
* Sets the neighbor info response.
*
* @param value The human-readable neighbor info string.
*/
Tff7b72override Tff7b72fun Td2a8ffsetNeighborInfoResponseTb4b4b4(Te6edf3valueTb4b4b4: Tffa657String?Tb4b4b4)

T8b949e/** Clears the current neighbor info response. */
Tff7b72override Tff7b72fun Td2a8ffclearNeighborInfoResponseTb4b4b4(Tb4b4b4)

Tff7b72companion Tff7b72object Tb4b4b4{
T8b949e/**
* The cross-module contract for the WiFi/TCP handshake-watchdog recovery progress signal.
*
* [MeshConnectionManager] writes this exact literal to [connectionProgress] immediately before its recovery
* sibling transitions the transport to [ConnectionState.Disconnected], and `ConnectionsViewModel` (and its
* tests) compare incoming progress against it to surface `RECONNECTING` UI state instead of a final-feeling
* `NOT_CONNECTED`. The literal text and the U+2026 HORIZONTAL ELLIPSIS character MUST match exactly across both
* writers and readers — centralizing it here removes the prior cross-module string-contract hazard.
*/
Tff7b72const Tff7b72val Te6edf3RECONNECTING_PROGRESS_TEXT Tff7b72= Ta5d6ff"Ta5d6ffReconnectingTa5d6ff\Ta5d6ffu2026Ta5d6ff"
Tb4b4b4}

T8b949e/** Reactive flow of the current lockdown authentication state. */
Tff7b72val Te6edf3lockdownStateTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3LockdownStateTff7b72>

T8b949e/** Updates the lockdown state. */
Tff7b72fun Td2a8ffsetLockdownStateTb4b4b4(Te6edf3stateTb4b4b4: Te6edf3LockdownStateTb4b4b4)

T8b949e/** Resets lockdown state to [LockdownState.None]. */
Tff7b72fun Td2a8ffclearLockdownStateTb4b4b4(Tb4b4b4)

T8b949e/** Reactive flow of the most recent lockdown session token info. */
Tff7b72val Te6edf3lockdownTokenInfoTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3LockdownTokenInfo?Tff7b72>

T8b949e/** Sets the lockdown token info from a successful UNLOCKED status. */
Tff7b72fun Td2a8ffsetLockdownTokenInfoTb4b4b4(Te6edf3infoTb4b4b4: Te6edf3LockdownTokenInfo?Tb4b4b4)

T8b949e/** True once the passphrase was accepted for the current BLE connection. */
Tff7b72val Te6edf3sessionAuthorizedTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657BooleanTff7b72>

T8b949e/** Updates the session authorization flag. */
Tff7b72fun Td2a8ffsetSessionAuthorizedTb4b4b4(Te6edf3authorizedTb4b4b4: Tffa657BooleanTb4b4b4)
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s